/*
 * Copyright 2020-2025 the original author or authors.
 * You cannot use this file unless authorized by the author.
 */
package org.ipig.commons.service;

/**
 * Generic Executor Chain
 *
 * @author <a href="mailto:comchnts@163.com">chinats</a>
 * @version $$Id: GenericExecutorChain.java 3 2020-01-21 09:36:33Z ts <comchnts@163.com> $$
 * @since 1.0
 */
public final class GenericExecutorChain<IN, OUT> implements ExecutorChain<IN, OUT> {
    private int pos = 0; //当前执行executor的offset
    private int n; //当前executor的数量
    private GenericExecutorConfig[] executors; //filter配置类，通过getFilter()方法获取Filter

    @Override
    public OUT invoke(IN in) throws Throwable {
        if (pos < n) {
            GenericExecutorConfig executorConfig = executors[pos++];
            ExecutorService executor = executorConfig.getExecutor();
            executor.execute();
        }
        return null;
    }
}
